package converter;

import com.gitee.feizns.dynamic.convert.Converts;
import com.gitee.feizns.dynamic.convert.ParseToNumberUtils;
import lombok.ToString;

/**
 * @author feizns
 * @since 2019/6/15 0015
 */
public class ConvertRegistryDemo {

    public static void main(String[] args) {

        Converts.registry((original, targetType) -> new User(ParseToNumberUtils.to(original, int.class)));

        User user = Converts.to(1, User.class);
        User user1 = Converts.to(2.1f, User.class);
        User user2 = Converts.to(3.3d, User.class);

        System.out.println(user);       //ConvertValueOfDemo.Role(id=1)
        System.out.println(user1);      //ConvertValueOfDemo.Role(id=2)
        System.out.println(user2);      //ConvertValueOfDemo.Role(id=3)

    }

    @ToString
    private static class User {

        private final Integer id;

        public User(Integer id) {
            this.id = id;
        }

    }

}
